package com.xxx;

import jdk.internal.dynalink.support.ClassLoaderGetterContextProvider;

import java.sql.*;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.util.*;

public class TakeawayMethod {
    ResourceBundle bundle = ResourceBundle.getBundle("resource/db");
    String driver = bundle.getString("driver");
    String url = bundle.getString("url");
    String user = bundle.getString("user");
    String password = bundle.getString("password");
    Scanner sc = new Scanner(System.in);
    Connection conn;
    Statement stmt;
    ResultSet rs;
    List<Dishes> ls = new ArrayList<>();
    List business = new ArrayList();
    List userlogin = new ArrayList();
    public void start(){
        conn = null;
        stmt = null;
        rs = null;
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url,user,password);
            stmt = conn.createStatement();
            while (true) {
                System.out.println("===========漂亮团外卖系统===========");
                System.out.println("1.登录");
                System.out.println("2.用户注册");
                System.out.println("3.商家注册");
                System.out.println("请输入操作命令:");
                int temp = sc.nextInt();
                switch (temp){
                    case 1:
                        login();
                        break;
                    case 2:
                        userEnroll();
                        break;
                    case 3:
                        businessEnroll();
                        break;
                    default:
                        System.out.println("没有该命令请重新确认");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (conn != null){
                try {
                    conn.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (stmt != null){
                try {
                    stmt.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (rs != null){
                try {
                    rs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }

    private void userEnroll() {
        try {
            System.out.println("请您输入您的用户名");
            String username = sc.next();
            System.out.println("请输入您的密码");
            String password2 = sc.next();
            System.out.println("请输入您的电话");
            String iphone = sc.next();
            System.out.println("请输入您的性别");
            String sex1 = sc.next();
            char sex=sex1.charAt(0);
            System.out.println("请您输入身份证号");
            String IdNumber = sc.next();
            System.out.println("请输入您的地址");
            String address = sc.next();
            String sql = "insert into user (`name`,password,sex,iphone,address) values ('"+username+"','"+password2+"','"+sex+"','"+iphone+"','"+address+"')";
            int i = stmt.executeUpdate(sql);
            if (i>0){
                System.out.println("恭喜您注册成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void businessEnroll() {
        try {
            System.out.println("请输入您的店长名");
            String name = sc.next();
            System.out.println("请输入您的店名");
            String shopname = sc.next();
            System.out.println("请输入您的密码");
            String password2 = sc.next();
            System.out.println("请输入您的电话");
            String iphone = sc.next();
            System.out.println("请输入您的地址");
            String address = sc.next();
            String intosql = "insert into `business` (`name`,`shopname`,password,iphone,address) values ('"+name+"','"+shopname+"','"+password2+"','"+iphone+"','"+address+"')";
            int i = stmt.executeUpdate(intosql);
            if (i>0){
                System.out.println("恭喜您注册成功");
            }
            String sql ="select id from business where name='"+name+"'";
            rs = stmt.executeQuery(sql);
            while (rs.next()){
                System.out.println("您的id为:"+rs.getString(1));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void login() {
        while (true) {
            System.out.println("请输入:");
            System.out.println("1.用户登录");
            System.out.println("2.商家登录");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    userlogin();
                    return;
                case 2:
                    businesslogin();
                    return;
                default:
                    System.out.println("没有该指令请重新确认!");
            }
        }
    }

    private void businesslogin() {
        try {
            while (true) {
                System.out.println("请输入id");
                String businessid = sc.next();
                System.out.println("请输入密码");
                String businesspassword = sc.next();
                String seletsql = "select id,password,`name` from business";
                rs = stmt.executeQuery(seletsql);
                while (rs.next()){
                    String id = rs.getString(1);
                    String password = rs.getString(2);
                    if (businessid.equals(id)&&businesspassword.equals(password)){
                        System.out.println("恭喜您登录成功!");
                        String name = rs.getString(3);
                        business.add(name);
                        System.out.println(business.get(0));
                        businessStart();
                        return;
                    }
                }
                System.out.println("您输入的账号密码有误请重新确认!~~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void businessStart() {//登录成功商家界面
        while (true) {
            System.out.println("~~~~商家界面~~~~");
            System.out.println("请输入您的选项:");
            System.out.println("1.员工管理");
            System.out.println("2.分类管理");
            System.out.println("3.菜品管理");
            System.out.println("4.套餐管理");
            System.out.println("5.订单管理");
            System.out.println("6.订单明细管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    employee();
                    break;
                case 2:
                    classify();
                    break;
                case 3:
                    dishes();
                    break;
                case 4:
                    packag();
                    break;
                case 5:
                    orders();
                    break;
                case 6:
                    Details();
                    break;
                default:
                    System.out.println("您输入的命令有误请重新确认!~~");
            }
        }
    }

    private void Details() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加订单明细");
            System.out.println("2.删除订单明细");
            System.out.println("3.修改订单明细");
            System.out.println("4.查询订单明细");
            System.out.println("5.退出订单明细管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addDetails();
                    break;
                case 2:
                    deletDetails();
                    break;
                case 3:
                    updateDetails();
                    break;
                case 4:
                    showDetails();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showDetails() {
        try {
            System.out.println("请您输入您要修改该订单表的订单id");
            String did = sc.next();
            System.out.println("请您输入您要修改该订单表的菜品id");
            String cid = sc.next();
            System.out.println("请您输入您要修改该订单表的套餐id");
            String tid = sc.next();
            String seletsql = "select `name`,`image`,`taste`,`quantity`,`money` from Order_Details where `Order`='"+did+"' and `dishes`='"+cid+"' and `Setmeal`='"+tid+"'";
            rs = stmt.executeQuery(seletsql);
            if (rs.next()){
                System.out.print("名称:"+rs.getString(1)+"  ");
                System.out.print("图片:"+rs.getString(2)+"  ");
                System.out.print("口味:"+rs.getString(3)+"  ");
                System.out.print("数量:"+rs.getString(4)+"  ");
                System.out.println("金额:"+rs.getString(5));
            }else {
                System.out.println("您输入的id有误呢");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void updateDetails() {
        try {
            System.out.println("请您输入您要修改该订单表的订单id");
            String did = sc.next();
            System.out.println("请您输入您要修改该订单表的菜品id");
            String cid = sc.next();
            System.out.println("请您输入您要修改该订单表的套餐id");
            String tid = sc.next();
            System.out.println("请输入您要修改的订单名称");
            String name = sc.next();
            System.out.println("请输入要修改的口味");
            String taste = sc.next();
            System.out.println("请输入修改的数量");
            String number = sc.next();
            System.out.println("请输入要修改的金额");
            String price = sc.next();
            String updasql = "update Order_Details set `name`='"+name+"',`taste`='"+taste+"',`quantity`='"+number+"',`money`='"+price+"' where `Order`='"+did+"' and `dishes`='"+cid+"' and `Setmeal`='"+tid+"'";
            int i = stmt.executeUpdate(updasql);
            if(i>0){
                System.out.println("修改成功");
            }else {
                System.out.println("您输入的id不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletDetails() {
        try {
            System.out.println("请您输入您要删除该订单表的订单id");
            String did = sc.next();
            System.out.println("请您输入您要删除该订单表的菜品id");
            String cid = sc.next();
            System.out.println("请您输入您要删除该订单表的套餐id");
            String tid = sc.next();
            String deletsql = "delete from order_details where `Order`='"+did+"' and `dishes`='"+cid+"' and `Setmeal`='"+tid+"'";
            int i = stmt.executeUpdate(deletsql);
            if (i>0){
                System.out.println("删除成功");
            }else {
                System.out.println("您输入的id有误请重新确认");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addDetails() {
        try {
            System.out.println("请输入您要添加的订单名字");
            String name = sc.next();
            System.out.println("请输入您要添加的订单图片");
            String image = sc.next();
            System.out.println("请输入您要添加的订单id");
            String did = sc.next();
            System.out.println("请输入您要添加的菜品id");
            String cid = sc.next();
            System.out.println("请输入您要添加的套餐id");
            String tid = sc.next();
            System.out.println("请输入您要添加的口味");
            String taste = sc.next();
            System.out.println("请输入要添加的数量");
            String number = sc.next();
            System.out.println("请输入要添加的金额");
            String price = sc.next();
            String intosql = "insert into Order_Details (`name`,`image`,`Order`,`dishes`,`Setmeal`,`taste`,`quantity`,`money`) values ('"+name+"','"+image+"','"+did+"','"+cid+"','"+tid+"','"+taste+"','"+number+"','"+price+"')";
            int i = stmt.executeUpdate(intosql);
            if (i>0){
                System.out.println("添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void orders() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加订单");
            System.out.println("2.删除订单");
            System.out.println("3.修改订单");
            System.out.println("4.查询订单");
            System.out.println("5.退出订单管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addorders();
                    break;
                case 2:
                    deletorders();
                    break;
                case 3:
                    updateorders();
                    break;
                case 4:
                    showorders();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showorders() {
        try {
            System.out.println("请输入您要查询的订单id");
            String id = sc.next();
            String seletsql = "select `orders_status`,`user`,`CheckoutTime`,`PaymentMethods`,`money`,`remark`,`phone`,`address` from orders where id='"+id+"'";

            rs = stmt.executeQuery(seletsql);
            if (rs.next()){
                System.out.print("订单状态:"+rs.getString(1)+"  ");
                System.out.print("订单用户:"+rs.getString(2)+"  ");
                System.out.print("订单付款时间:"+rs.getString(3)+"  ");
                System.out.print("订单支付方法:"+rs.getString(4)+"  ");
                System.out.print("订单的金额:"+rs.getString(5)+"  ");
                System.out.print("订单的备注:"+rs.getString(6)+"  ");
                System.out.print("订单的电话号码:"+rs.getString(7)+"  ");
                System.out.println("订单的地址:"+rs.getString(8));
            }else {
                System.out.println("您输入的id有误");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void updateorders() {
        try {
            System.out.println("请输入您要修改的id");
            String id = sc.next();
            System.out.println("请输入您要修改的订单用户");
            String username = sc.next();
            System.out.println("请输入您要修改的备注");
            String remark = sc.next();
            System.out.println("请输入您要修改的电话");
            String iphone = sc.next();
            System.out.println("请您输入要修改的地址");
            String address = sc.next();
            String updasql = "update orders set `user`='"+username+"',`remark`='"+remark+"',`phone`='"+iphone+"',`address`='"+address+"',`user_name`='"+username+"' where id='"+id+"'";

            int i = stmt.executeUpdate(updasql);
            if (i>0){
                System.out.println("修改成功");
            }else {
                System.out.println("您输入的id有误呢");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletorders() {
        try {
            System.out.println("请您输入要删除的订单id");
            String id = sc.next();
            String deletsql = "delete from orders where id='"+id+"'";
            int i = stmt.executeUpdate(deletsql);
            if (i>0){
                System.out.println("删除成功");
            }else {
                System.out.println("你输入的id有误请重新确认!~~");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    private void addorders() {
        if (ls.size()<1){
            System.out.println("当前没有用户订单");
            return;
        }
        System.out.println("当前的用户订单如下:");
        for (Dishes l : ls) {
            System.out.println("-----------------------");
            System.out.print("id:"+l.getId()+"  ");
            System.out.print("菜品名称:"+l.getName()+"  ");
            System.out.println("价格"+l.getPrice()+"  ");
        }
        String userid = (String) userlogin.get(0);
        try {
            for (Dishes l : ls) {
                double price = l.getPrice();
                String remark = l.getRemark();
                rs = stmt.executeQuery("select iphone,address,`name` from user where `id`='"+userid+"'");
                while (rs.next()){
                    String iphone = rs.getString("iphone");
                    String address = rs.getString("address");
                    String name = rs.getString("name");
                    String time = LocalDateTime.now().toString();
                    Statement statement = conn.createStatement();
                    int i = statement.executeUpdate("insert into `orders` (`user`,`CheckoutTime`,`PaymentMethods`,`money`,`remark`,`phone`,`address`,`user_name`) values ('" + name + "','" + time + "',1,'" + price + "','" + remark + "','" + iphone + "','" + address + "','" + name + "')");
                    if (i>0){
                        System.out.println("添加成功");
                        ResultSet resultSet = statement.executeQuery("select id from orders where `user`='" + name + "'");
                        if (resultSet.next()){
                            System.out.println("您的id为:"+resultSet.getString("id"));
                            resultSet.close();
                        }
                    }
                    statement.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void packag() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加套餐");
            System.out.println("2.删除套餐");
            System.out.println("3.修改套餐");
            System.out.println("4.查询套餐");
            System.out.println("5.退出套餐管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addpackage();
                    break;
                case 2:
                    deletpackage();
                    break;
                case 3:
                    revisepackage();
                    break;
                case 4:
                    seletpackage();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void seletpackage() {
        try {
            rs = stmt.executeQuery("select * from package");
            if (rs.next()){
                System.out.println("请输入你要查询的菜品");
                String name = sc.next();
                String seletsql = "select dishes.name from dishes,package where dishes.cid=package.cid and package.name='"+name+"'";
                rs = stmt.executeQuery(seletsql);
                if (rs.next()){
                    System.out.print(name+"的套餐有以下菜品: "+rs.getString("name")+"  ");
                    while (rs.next()){
                        System.out.print(rs.getString("name")+"  ");
                    }
                    System.out.println();
                }else {
                    System.out.println("您输入的套餐名称不存在");
                }
            }else {
                System.out.println("当前没有任何套餐请先去添加吧!~~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void revisepackage() {
        try {
            System.out.println("请输入您要修改的套餐名称");
            String name = sc.next();
            System.out.println("请输入您要修改该套餐的菜品id");
            String id = sc.next();
            String updatesql = "update package set `cid`='"+id+"' where `name`='"+name+"' and `cid`='"+id+"'";
            int i = stmt.executeUpdate(updatesql);
            if(i>0){
                System.out.println("修改成功");
            }else {
                System.out.println("您输入的名称或菜品id有误请重新确认");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletpackage() {
        try {
            System.out.println("请输入您要删除的套餐名称");
            String name = sc.next();
            String deletsql = "delete from package where `name`='"+name+"'";
            int i = stmt.executeUpdate(deletsql);
            if (i>0){
                System.out.println("删除成功");
            }else {
                System.out.println("您输入的套餐名称不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addpackage() {
        try {
            System.out.println("请输入您要添加的菜品id");
            String id = sc.next();
            System.out.println("套餐名称");
            String name = sc.next();
            System.out.println("套餐价格");
            String price = sc.next();
            System.out.println("请输入该套餐的编码");
            String encode = sc.next();
            System.out.println("请输入描述信息");
            String description = sc.next();
            System.out.println("请输入图片");
            String image = sc.next();
            String time = LocalDateTime.now().toString();
            String cread = (String)business.get(0);
            String intosql = "insert into package (`cid`,`name`,`price`,`encode`,`DescriptiveInformation`,`image`,`create_time`,`update_time`,`create_user`,`update_user`) values ('"+id+"','"+name+"','"+price+"','"+encode+"','"+description+"','"+image+"','"+time+"','"+time+"','"+cread+"','"+cread+"')";
            int i = stmt.executeUpdate(intosql);
            if (i>0){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void dishes() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加菜品");
            System.out.println("2.删除菜品");
            System.out.println("3.修改菜品");
            System.out.println("4.查询菜品");
            System.out.println("5.退出菜品管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    adddishes();
                    break;
                case 2:
                    deletdishes();
                    break;
                case 3:
                    revisedishes();
                    break;
                case 4:
                    showdishes();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showdishes() {
        try {
            rs = stmt.executeQuery("select * from dishes");
            if (rs.next()){
                System.out.println("请输入您要查询的菜品id");
                String id = sc.next();
                String seletsql = "select `name`,`cid`,`price`,`productcode`,`image`,`description`,`status` from dishes where cid='"+id+"'";

                rs = stmt.executeQuery(seletsql);
                if (rs.next()){
                    System.out.print("菜品名称:"+rs.getString("name")+"  ");
                    System.out.print("菜品id:"+rs.getString("cid")+"  ");
                    System.out.print("菜品价格:"+rs.getString("price")+"  ");
                    System.out.print("商品码:"+rs.getString("productcode")+"  ");
                    System.out.print("菜品图片:"+rs.getString("image")+"  ");
                    System.out.print("描述信息:"+rs.getString("description")+"  ");
                    System.out.println("菜品状态:"+rs.getString("status"));
                }else {
                    System.out.println("您输入的id有误请重新确认");
                }
            }else {
                System.out.println("当前没有人任何菜品请先去添加吧");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void revisedishes() {
        try {
            System.out.println("请输入您要修改的id");
            String id = sc.next();
            System.out.println("请输入您要修改的菜品名称");
            String name = sc.next();
            System.out.println("请输入您要修改的菜品价格");
            String price = sc.next();
            System.out.println("请输入您要修改的商品码");
            String code = sc.next();
            System.out.println("请输入您要修改的菜品图片");
            String image = sc.next();
            System.out.println("请输入修改后菜品的描述信息");
            String description = sc.next();
            String upda = (String) business.get(0);
            String time = LocalDateTime.now().toString();
            String update = "update dishes set `name`='"+name+"',`price`='"+price+"',`productcode`='"+code+"',`image`='"+image+"',`description`='"+description+"',`update_time`='"+time+"',`update_user`='"+upda+"' where cid='"+id+"'";

            int i = stmt.executeUpdate(update);
            if (i>0){
                System.out.println("修改成功");
            }else {
                System.out.println("您输入的id有误请重新确认");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletdishes() {
        try {
            System.out.println("请输入您要删除的菜品id");
            String id = sc.next();
            String deletsql = "delete from dishes where cid='"+id+"'";
            int i = stmt.executeUpdate(deletsql);
            if (i>0){
                System.out.println("删除成功");
            }else {
                System.out.println("您输入的id有误请重新确认");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void adddishes() {
        try {
            System.out.println("请输入您要添加的菜品名称");
            String name = sc.next();
            System.out.println("请输入您要添加的菜品id");
            String id = sc.next();
            System.out.println("请输入您要添加的菜品价格");
            String price = sc.next();
            System.out.println("请输入您要添加的商品码");
            String code = sc.next();
            System.out.println("请输入您要添加的菜品图片");
            String image = sc.next();
            System.out.println("请输入该菜品的描述信息");
            String description = sc.next();
            String create = (String) business.get(0);
            String time = LocalDateTime.now().toString();
            System.out.println(time);
            String intosql = "insert into `dishes` (`name`,`cid`,`price`,`productcode`,`image`,`description`,`create_time`,`update_time`,`create_user`,`update_user`) values ('"+name+"','"+id+"','"+price+"','"+code+"','"+image+"','"+description+"','"+time+"','"+time+"','"+create+"','"+create+"')";
            int i = stmt.executeUpdate(intosql);
            if (i>0){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void classify() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加分类");
            System.out.println("2.删除分类");
            System.out.println("3.修改分类");
            System.out.println("4.查询分类");
            System.out.println("5.退出分类管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addclassify();
                    break;
                case 2:
                    deletclassify();
                    break;
                case 3:
                    reviseclassify();
                    break;
                case 4:
                    showclassify();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showclassify() {
        try {
            rs = stmt.executeQuery("select * from classify");
            if (rs.next()){
                System.out.println("请输入您要查询的id");
                String id = sc.next();
                String seletsql = "select type,classname,id from classify where id='"+id+"'";
                rs = stmt.executeQuery(seletsql);
                if (rs.next()){
                    System.out.print("分类:"+rs.getString("type")+"  ");
                    System.out.print("分类名称"+rs.getString("classname")+"  ");
                    System.out.println("id:"+rs.getString("id"));
                }else {
                    System.out.println("没有当前id请重新确认");
                }
            }else {
                System.out.println("当前没有任何分类菜单请先去添加!~~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void reviseclassify() {
        try {
            System.out.println("请输入您要修改的id号");
            String id = sc.next();
            System.out.println("请输入修改后的分类");
            String type = sc.next();
            System.out.println("请输入修改后的分类名称");
            String classname = sc.next();
            String upda = (String) business.get(0);
            LocalDateTime time = LocalDateTime.now();
            String date = time.toString();
            String update = "update classify set type='"+type+"',classname='"+classname+"',update_time='"+date+"',update_user='"+upda+"' where id='"+id+"'";
            int i = stmt.executeUpdate(update);
            if (i>0){
                System.out.println("恭喜您修改成功");
            }else {
                System.out.println("没有当前id请重新确认!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletclassify() {
        try {
            System.out.println("请输入您要删除的id");
            String id = sc.next();
            String deletsql = "delete from classify where id='"+id+"'";
            int i = stmt.executeUpdate(deletsql);
            if (i>0){
                System.out.println("恭喜您删除成功!");
            }else {
                System.out.println("删除失败，您输入的id不正确或没有该id");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addclassify() {
        try {
            System.out.println("请输入您要添加的分类类型");
            String type = sc.next();
            System.out.println("请输入您要添加的分类名称");
            String classname = sc.next();
            String create = (String) business.get(0);
            LocalDateTime time = LocalDateTime.now();
            String date = time.toString();
            String intosql = "insert into `classify` (`type`,`classname`,`create_time`,`update_time`,`create_user`,`update_user`) values ('"+type+"','"+classname+"','"+date+"','"+date+"','"+create+"','"+create+"')";
            int i = stmt.executeUpdate(intosql);
            if (i>0){
                System.out.println("恭喜您添加成功!");
                rs = stmt.executeQuery("select `type`,`id` from classify where type='"+type+"'");
                while (rs.next()){
                    System.out.println("您的id为:"+rs.getString("id"));
                }
            }else {
                System.out.println("插入失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void employee() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加员工");
            System.out.println("2.删除员工");
            System.out.println("3.修改员工");
            System.out.println("4.查询员工");
            System.out.println("5.退出员工管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addemployee();
                    break;
                case 2:
                    deltemployee();
                    break;
                case 3:
                    reviseemployee();
                    break;
                case 4:
                    showemployee();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showemployee() {
        try {
            rs = stmt.executeQuery("select * from employee");
            if (rs.next()){
                System.out.println("请输入您要查找的id");
                String id = sc.next();
                String seletsql = "select * from employee where id='"+id+"'";
                rs = stmt.executeQuery(seletsql);
                if (rs.next()){
                    System.out.print("姓名:"+rs.getString("name")+"  ");
                    System.out.print("用户名:"+rs.getString("username")+"  ");
                    System.out.print("密码:"+rs.getString("password")+"  ");
                    System.out.print("电话:"+rs.getString("phone")+"  ");
                    System.out.print("性别:"+rs.getString("sex")+"  ");
                    System.out.print("身份证号:"+rs.getString("id_number")+"  ");
                    System.out.println("当前状态:"+rs.getString("status"));
                }else {
                    System.out.println("没有当前id请重新确认");
                }
            }else {
                System.out.println("当前没有任何员工,请去添加员工");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void reviseemployee() {
        try {
            System.out.println("请输入您要修改的员工id");
            String id = sc.next();
            System.out.println("请输入修改后的名字");
            String name = sc.next();
            System.out.println("请输入修改后的用户名");
            String username = sc.next();
            System.out.println("请输入修改后的密码");
            String password = sc.next();
            System.out.println("请输入修改后的电话");
            String iphone = sc.next();
            System.out.println("请输入修改后的性别");
            String sex = sc.next();
            System.out.println("请输入修改后的身份证");
            String card = sc.next();
            String update = (String) business.get(0);
            LocalDateTime time = LocalDateTime.now();
            String date = time.toString();
            String updatesql = "update employee set name='"+name+"',username='"+username+"',password='"+password+"',phone='"+iphone+"',sex='"+sex+"',id_number='"+card+"',update_time='"+date+"',update_user='"+update+"' where id='"+id+"'";
            int i = stmt.executeUpdate(updatesql);
            if (i>0){
                System.out.println("修改成功");
            }else {
                System.out.println("您输入的id有误");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deltemployee() {
        try {
            System.out.println("请输入该员工的id");
            String id = sc.next();
            String deletsql = "DELETE from employee where id='"+id+"'";
            int i = stmt.executeUpdate(deletsql);
            if (i>0){
                System.out.println("删除成功");
            }else {
                System.out.println("没有该员工请重新确认!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addemployee() {
        try {
            System.out.println("请输入员工id");
            String id = sc.next();
            System.out.println("请输入员工姓名");
            String name = sc.next();
            System.out.println("请输入员工用户名");
            String username = sc.next();
            System.out.println("请输入员工密码");
            String password = sc.next();
            System.out.println("请输入员工手机号");
            String iphone = sc.next();
            System.out.println("请输入员工性别");
            String sex = sc.next();
            System.out.println("请输入员工身份证号");
            String card = sc.next();
            LocalDateTime time = LocalDateTime.now();
            String date = time.toString();
            String creadname = (String) business.get(0);
            String intosql = "insert into `employee` (`id`,`name`,`username`,`password`,`phone`,`sex`,`id_number`," +
                    "`create_time`,`update_time`,`create_user`,`update_user`) values " +
                    "('"+id+"','"+name+"','"+username+"','"+password+"','"+iphone+"','"+sex+"','"+card+"','"+date+"','"+date+"','"+creadname+"','"+creadname+"')";
            int i = stmt.executeUpdate(intosql);
            if (i>0){
                System.out.println("添加成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void userlogin() {
        try {
            while (true) {
                System.out.println("请输入id");
                String userid = sc.next();
                System.out.println("请输入密码");
                String userpassword = sc.next();
                String sql = "select id,password from user";
                rs = stmt.executeQuery(sql);
                while (rs.next()){
                    String id = rs.getString(1);
                    String password = rs.getString(2);
                    if(userid.equals(id)&&userpassword.equals(password)){
                        System.out.println("恭喜您登录成功");
                        userlogin.add(id);
                        userstart();
                        return;
                    }
                }
                System.out.println("您输入的账号或密码不正确请重新确认!~~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void userstart() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.我要订餐:");
            System.out.println("2.查看订单:");
            System.out.println("3.签收订单:");
            System.out.println("4.删除订单:");
            System.out.println("5.我要点赞:");
            System.out.println("6.退出系统:");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    OrderFood();
                    break;
                case 2:
                    ShowOrder();
                    break;
                case 3:
                    SignOrder();
                    break;
                case 4:
                    deletOrder();
                    break;
                case 5:
                    Thumbsup();
                    break;
                case 6:
                    return;
            }
        }
    }

    private void Thumbsup() {//点赞因为在数据库中没有设置该类型所以先省略了
    }

    private void deletOrder() {
        if (ls.size()<1){
            System.out.println("当前没有任何订单!");
            return;
        }
        System.out.println("订单信息如下:");
        for (Dishes l : ls) {
            System.out.print(l.getId()+"  ");
            System.out.print(l.getName()+"  ");
            System.out.println(l.getPrice());
        }
        while (true) {
            System.out.println("输入您要删除的订单id");
            String id = sc.next();
            for (Dishes l : ls) {
                if (id.equals(l.getId())){
                    ls.remove(l);
                    System.out.println("删除成功");
                    return;
                }
            }
            System.out.println("没有该订单,请重新输入");
        }
    }

    private void SignOrder() {
        if (ls.size()<1){
            System.out.println("当前没有任何订单!");
            return;
        }
        System.out.println("订单信息如下:");
        for (Dishes l : ls) {
            System.out.print(l.getId()+"  ");
            System.out.print(l.getName()+"  ");
            System.out.println(l.getPrice());
        }
        while (true) {
            System.out.println("请输入您要签收的订单id");
            String id = sc.next();
            for (Dishes l : ls) {
                if (id.equals(l.getId())&&l.getState().equals("0")){
                    l.setState("1");
                    System.out.println("签收成功!");
                    return;
                }else if(id.equals(l.getId())&&l.getState().equals("0")){
                    System.out.println("该订单已经签收过了!");
                }
            }
            System.out.println("没有该订单");
        }
    }

    private void ShowOrder() {
        if (ls.size()<1){
            System.out.println("当前没有任何订单!");
            return;
        }
        System.out.println("订单信息如下:");
        for (Dishes l : ls) {
            System.out.print(l.getId()+"  ");
            System.out.print(l.getName()+"  ");
            System.out.println(l.getPrice());
        }
    }

    private void OrderFood() {
        try {
            String sql = "select name,cid,price,description from dishes";
            rs = stmt.executeQuery(sql);
            if(rs.next()){
                System.out.println("菜单如下");
                System.out.print(rs.getString("name")+"  ");
                System.out.print(rs.getString("cid")+"  ");
                System.out.print(rs.getString("price")+"  ");
                System.out.println(rs.getString("description"));
                while (rs.next()){
                    System.out.print(rs.getString("name")+"  ");
                    System.out.print(rs.getString("cid")+"  ");
                    System.out.print(rs.getString("price")+"  ");
                    System.out.println(rs.getString("description"));
                }
                System.out.println("请输入您想定的菜id序号");
                String id = sc.next();
                System.out.println("请输入您的备注");
                String remark = sc.next();
                String selesql = "select name,cid,price,description from dishes where cid='"+id+"'";
                rs = stmt.executeQuery(selesql);
                if(rs.next()){
                    String sprice = rs.getString("price");
                    Double price = Double.valueOf(sprice);
                    ls.add(new Dishes(rs.getString("name"),rs.getString("cid"),price,rs.getString("description"),"0",remark));
                }
            }else {
                System.out.println("当前没有任何菜品请商家去上架菜品");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
